package com.nlelpct.manage.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.nlelpct.manage.model.query.TerminalInfo;
import com.nlelpct.manage.model.vo.ResponseResult;
import com.nlelpct.manage.service.IValidateService;
import com.nlelpct.manage.utils.IDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author :小马
 * @date : 2023-07-20
 */
@Service
public class ValidateServiceImpl implements IValidateService {

    private final RedisTemplate<String, Object> redisTemplate;

    @Autowired
    public ValidateServiceImpl(RedisTemplate<String, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @Override
    public ResponseResult<String> saveTerminalInfo(TerminalInfo info) {
        String timeId = IDUtils.genRandom("Terminal:", 32);
        redisTemplate.opsForValue().set(timeId, JSONObject.toJSONString(info), 24L, TimeUnit.HOURS);
        return ResponseResult.success(timeId, "保存客户端信息成功！");
    }

}
